//
//  BVHotSearchCell.m
//  BuyVegetable
//
//  Created by yushanchang on 16/10/21.
//  Copyright © 2016年 com.yinding. All rights reserved.
//

#import "BVHotSearchCell.h"
#import "UIView+Extension.h"

@implementation BVHotSearchCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self.contentView setBackgroundColor:[UIColor BVBackgroundLightGrayColor]];
        [self setupContentView];
    }
    return self;
}

- (void)setupContentView {
    NSArray *titleArr = @[@"沙拉",@"冬枣",@"虾",@"沙拉",@"冬枣",@"虾",@"沙拉",@"冬枣",@"虾"];
    
    float ItemSpace = 5;
    float ItemX = 15;
    float ItemY = 0;
    float ItemWidth = (ScreenW - 15*2 - ItemSpace*2) / 3;
    float ItemHeight = 40;
    
    for(int i = 0; i < 9; i++) {
        UIButton * hotItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [hotItem setX:ItemX + (ItemWidth + ItemSpace) * (i % 3)];
        [hotItem setY:ItemY + (ItemHeight + ItemSpace) * (i / 3)];
        [hotItem setWidth:ItemWidth];
        [hotItem setHeight:ItemHeight];
        [hotItem.titleLabel setFont:[UIFont systemFontOfSize:15]];
        [hotItem setTitle:titleArr[i] forState:UIControlStateNormal];
        [hotItem setTitleColor:[UIColor BVBaseTextBlackColor] forState:UIControlStateNormal];
        [hotItem setBackgroundColor:[UIColor whiteColor]];
        [hotItem setTag:i + 1];
        [hotItem addTarget:self action:@selector(hotItemClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:hotItem];
    }
}

- (void)hotItemClick:(UIButton *)button {
    if (self.hotBlock) {
        self.hotBlock(button.tag,button.titleLabel.text);
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
